package ascii;

import java.awt.Color;

/**
 * Ansi color for BBS. There are only 16 colors in terminal, which are defined
 * here.
 * @author Guan-Zhong Huang
 * @date 0.1
 * @since 0.1
 */
public class AnsiColor {

    public final static Color BLACK;
    public final static Color RED;
    public final static Color GREEN;
    public final static Color YELLOW;
    public final static Color BLUE;
    public final static Color MAGENTA;
    public final static Color CYAN;
    public final static Color WHITE;
    public final static Color BRIGHT_BLACK;
    public final static Color BRIGHT_RED;
    public final static Color BRIGHT_GREEN;
    public final static Color BRIGHT_YELLOW;
    public final static Color BRIGHT_BLUE;
    public final static Color BRIGHT_MAGENTA;
    public final static Color BRIGHT_CYAN;
    public final static Color BRIGHT_WHITE;

    static {
        BLACK = new Color(0, 0, 0);
        RED = new Color(128, 0, 0);
        GREEN = new Color(0, 128, 0);
        YELLOW = new Color(128, 128, 0);
        BLUE = new Color(0, 0, 128);
        MAGENTA = new Color(128, 0, 128);
        CYAN = new Color(0, 128, 128);
        WHITE = new Color(192, 192, 192);
        BRIGHT_BLACK = new Color(128, 128, 128);
        BRIGHT_RED = new Color(255, 0, 0);
        BRIGHT_GREEN = new Color(0, 255, 0);
        BRIGHT_YELLOW = new Color(255, 255, 0);
        BRIGHT_BLUE = new Color(0, 0, 255);
        BRIGHT_MAGENTA = new Color(255, 0, 255);
        BRIGHT_CYAN = new Color(0, 255, 255);
        BRIGHT_WHITE = new Color(255, 255, 255);
    }

    public static String fgColorCode(int colorIndex) {
        return ((colorIndex >> 3) & 0x1) + ";" + ((colorIndex & 0x7) + 30);
    }

    public static String bgColorCode(int colorIndex) {
        return String.valueOf((colorIndex & 0x7) + 40);
    }
 }